package com.ruoyi.archive.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.archive.domain.ArchiveRoomHistory;
import com.ruoyi.archive.service.IArchiveRoomHistoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 变更记录Controller
 * 
 * @author yepanpan
 * @date 2025-04-17
 */
@RestController
@RequestMapping("/archive/history")
public class ArchiveRoomHistoryController extends BaseController
{
    @Autowired
    private IArchiveRoomHistoryService archiveRoomHistoryService;

    /**
     * 查询变更记录列表
     */
    @PreAuthorize("@ss.hasPermi('archive:history:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArchiveRoomHistory archiveRoomHistory)
    {
        startPage();
        List<ArchiveRoomHistory> list = archiveRoomHistoryService.selectArchiveRoomHistoryList(archiveRoomHistory);
        return getDataTable(list);
    }

    /**
     * 导出变更记录列表
     */
    @PreAuthorize("@ss.hasPermi('archive:history:export')")
    @Log(title = "变更记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArchiveRoomHistory archiveRoomHistory)
    {
        List<ArchiveRoomHistory> list = archiveRoomHistoryService.selectArchiveRoomHistoryList(archiveRoomHistory);
        ExcelUtil<ArchiveRoomHistory> util = new ExcelUtil<ArchiveRoomHistory>(ArchiveRoomHistory.class);
        util.exportExcel(response, list, "变更记录数据");
    }


    /**
     * 获取变更记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('archive:history:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(archiveRoomHistoryService.selectArchiveRoomHistoryById(id));
    }

    /**
     * 新增变更记录
     */
    @PreAuthorize("@ss.hasPermi('archive:history:add')")
    @Log(title = "变更记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody ArchiveRoomHistory archiveRoomHistory)
    {
        archiveRoomHistory.setCreateBy(getUsername());
        return toAjax(archiveRoomHistoryService.insertArchiveRoomHistory(archiveRoomHistory));
    }

    /**
     * 修改变更记录
     */
    @PreAuthorize("@ss.hasPermi('archive:history:edit')")
    @Log(title = "变更记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody ArchiveRoomHistory archiveRoomHistory)
    {
        archiveRoomHistory.setUpdateBy(getUsername());
        return toAjax(archiveRoomHistoryService.updateArchiveRoomHistory(archiveRoomHistory));
    }

    /**
     * 删除变更记录
     */
    @PreAuthorize("@ss.hasPermi('archive:history:remove')")
    @Log(title = "变更记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(archiveRoomHistoryService.deleteArchiveRoomHistoryByIds(ids));
    }
}
